package DesignPattern.PrototypePattern.demo2;

import java.io.*;

public class Prototype<T extends Prototype> implements Serializable {

    public T deepClone() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);

        ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
        Object object = objectInputStream.readObject();

        return (T) object;
    }

}
